<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="活动id">
              <j-input placeholder="请输入活动id" v-model="queryParam.policyid"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="活动名称">
              <j-input placeholder="请输入活动名称" v-model="queryParam.policyTitle"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="驿站名称">
              <j-input placeholder="请输入驿站名称" v-model="queryParam.corpname"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('活动报名')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px; ">
        <a style="font-weight: 600;">请输入活动id或唯一的活动名称,点击查询</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

      </a-table>
    </div>

    <lhyg-policy-bm-modal ref="modalForm" @ok="modalFormOk"></lhyg-policy-bm-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LhygPolicyBmModal from './modules/LhygPolicyBmModal'
  import JInput from '@/components/jeecg/JInput'
  import {getAction} from "@api/manage";

  export default {
    name: 'LhygPolicyBmList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      LhygPolicyBmModal,
      JInput,
    },
    data () {
      return {
        description: '活动报名管理页面',
        // 表头
        columns: [],
        // columns: [
        //   {
        //     title:'活动id',
        //     align:"center",
        //     dataIndex: 'policyid'
        //   },
        //   {
        //     title:'活动名称',
        //     align:"center",
        //     dataIndex: 'policyTitle'
        //   },
        //   {
        //     title:'所属驿站id',
        //     align:"center",
        //     dataIndex: 'ssyz'
        //   },
        //   {
        //     title:'驿站名称',
        //     align:"center",
        //     dataIndex: 'corpname'
        //   },
        //   {
        //     title:'用户id',
        //     align:"center",
        //     dataIndex: 'wxUserId'
        //   },
        //   {
        //     title:'内容',
        //     align:"center",
        //     dataIndex: 'content'
        //   }
        // ],
        url: {
          list: "/policybm/lhygPolicyBm/list",
          delete: "/policybm/lhygPolicyBm/delete",
          deleteBatch: "/policybm/lhygPolicyBm/deleteBatch",
          exportXlsUrl: "/policybm/lhygPolicyBm/exportXls",
          importExcelUrl: "policybm/lhygPolicyBm/importExcel",
          gettitle: "/policybm/lhygPolicyBm/gettitle",

        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },

      searchQuery() {
        this.loadData(1);
      },

      loadData(arg) {
        if(!this.url.list){
          // this.$message.error("请设置url.list属性!")
          return
        }

        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;

        getAction(this.url.gettitle, params).then((res) => {
          if (res.success) {
            this.columns = res.result;
          }

          if(res.code!=200){
            this.columns = [];
            this.dataSource = [];
            this.ipagination.total = 0;
            this.$message.warning(res.message)
          }
          this.loading = false;
          return
        })

        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>